/*

 * main.c
 *
 *  Created on: Sep 4, 2013
 *      Author: Alan
 */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "jjann.h"
//#include "activation.h"
#include "topology.h"
#include "training.h"
#include "constants.h"

int main(int argc, char** argv) {

	uint8 status;
	uint32 i, j;
	float32 error;
	float32 input[2], output[1];
	//trainingPattern_t *trainPatterns;
	trainingData_t trainingData;
	netdata_t* net;


	//srand(SEED);

	//status = read(&topo, "topology/221.top");

	net = initNetwork("configs/xor.cfg");

	loadSamples(&trainingData, "datasets/xor.training");
	fprintf(stderr, "Samples loaded\n");
	//feedForward(net, trainingData.samples[0].input, output);
	//fprintf(stderr, "++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	//debugMatrix(net);
	fprintf(stderr,"Training for %d epochs\n", net->settings.maxEpochs);
	for (i = 0; i < net->settings.maxEpochs; i++) {
		error = trainOneEpoch(net, trainingData.samples, 4);
		fprintf(stdout, "error: %f\n", error);
		//fprintf(stderr, "%d - - - - -- - - - - - - -- - - - - - -- - \n",i);
		//debugMatrix(net);
	}
	feedForward(net, trainingData.samples[0].input, output);
	fprintf(stderr, "%f XOR %f = %f\n", trainingData.samples[0].input[0], trainingData.samples[0].input[1], output[0]);

	feedForward(net, trainingData.samples[1].input, output);
	fprintf(stderr, "%f XOR %f = %f\n", trainingData.samples[1].input[0], trainingData.samples[1].input[1], output[0]);

	feedForward(net, trainingData.samples[2].input, output);
	fprintf(stderr, "%f XOR %f = %f\n", trainingData.samples[2].input[0], trainingData.samples[2].input[1], output[0]);

	feedForward(net, trainingData.samples[3].input, output);
	fprintf(stderr, "%f XOR %f = %f\n", trainingData.samples[3].input[0], trainingData.samples[3].input[1], output[0]);
	destroyNetwork(net);
	freeSamples(&trainingData);
}

